import { userApi } from '@/api'
const user = {
  state: {
    userInfo: {}
  },
  mutations: {
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo
    }
  },
  actions: {
    // 获取用户信息
    GetUserInfo ({ commit }, data) {
      return new Promise(resolve => {
        if (data) {
          commit('SET_USERINFO', data)
          resolve()
        } else {
          userApi.detail().then(res => {
            console.log(res)
            if (res && res.code === 0) {
              commit('SET_USERINFO', res.data)
              resolve(res.data)
            }
          })
        }
      })
    }
  }
}
export default user
